<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Map-方法</title>
</head>
<body>
<script>
  // 声明map -- 创建一个空对象
  let map=new Map();

  //添加元素
  map.set('name','zhangSan')
  map.set('age','15')
  map.set('sex','woman')
  //添加的元素  keys是string,values是函数
  map.set('eat',function (){
    console.log('I Love Eat Fish !')
  });
  //添加的元素  keys是对象,values是数组
  let key={
    name:'liSi',
    age:15
  }
  map.set(key,[1,'games'])
  console.log(map);

  //查看长度
  console.log(map.size)

  //删除
  map.delete('sex')
  console.log(map)

  //获取
  console.log(map.get('name'))
  console.log(map.keys())
  console.log(map.values())

  //遍历
  for (let value of map) {//遍历map
    console.log(value)
  }
  for (let value of map.keys()) {//遍历map的键
    console.log(value)
  }
  for (let value of map.values()) {//遍历map的值
    console.log(value)
  }
</script>
</body>
</html>